<%--
  Created by IntelliJ IDEA.
  User: 20275
  Date: 2023/11/18
  Time: 16:16
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%@include file="/pages/common/head.jsp"%>

<script>
    function previewAvatar() {
        var fileInput = document.getElementById('avatarInput');
        var avatarImg = document.getElementById('avatarImg');

        // 获取选中的文件
        var file = fileInput.files[0];

        // 创建 FileReader 对象
        var reader = new FileReader();

        // 设置文件加载完成后的回调函数
        reader.onload = function(e) {
            // 在头像图片中显示图像
            avatarImg.src = e.target.result;
        };

        // 读取文件内容
        reader.readAsDataURL(file);
    }

    function openFileInput() {
        var fileInput = document.getElementById('avatarInput');
        fileInput.click();
    }
</script>

<div id="page-wrapper">
    <div class="row">
        <div class="col-lg-12">
            <h1 class="page-header">个人信息</h1>
        </div>
    </div>
    <div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    填写个人信息
                </div>
                <div class="panel-body">
                    <form role="form" action="${pageContext.request.contextPath }/studentManage/updateOneStu" method="post" enctype="multipart/form-data">

                        <div class="row">
                            <div class="col-lg-6">
                                <input  name="studentId" value="${stu_info.studentId}" type="hidden">
                                <input  name="studentImgName" value="${stu_info.studentImgName}" type="hidden">

                                <div class="form-group">
                                    <!-- 头像区域和上传按钮 -->
                                    <div class="avatar-wrapper">
                                        <img id="avatarImg" class="avatar" src="${pageContext.request.contextPath }/img/${stu_info.studentImgName}" alt="头像">
                                        <a class="upload-btn" onclick="openFileInput()">上传头像</a>
                                    </div>
                                    <!-- 文件选择框 -->
                                    <input id="avatarInput" type="file" class="hidden" onchange="previewAvatar()" name="imageFile"  accept="image/*">
                                </div>
                                <div class="form-group">
                                    <label>学号</label>
                                    <input class="form-control" value="${stu_info.studentNumber}" readonly>
                                </div>
                                <div class="form-group">
                                    <label>姓名</label>
                                    <input class="form-control" name="studentName" value="${stu_info.studentName}" required>
                                </div>
                                <div class="form-group">
                                    <label>性别</label>
                                    <select class="form-control" name="studentGender" required>
                                        <c:if test="${stu_info.studentGender == 1}">
                                            <option value="1" selected> 男</option>
                                            <option value="0">女</option>
                                        </c:if>
                                        <c:if test="${stu_info.studentGender == 0}">
                                            <option value="1"> 男</option>
                                            <option value="0" selected>女</option>
                                        </c:if>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>名族</label>
                                    <input class="form-control" name="studentFamilial" value="${stu_info.studentFamilial}" required>
                                </div>
                            </div>
                            <div class="col-lg-6">
                                <div class="form-group">
                                    <label>身份证</label>
                                    <input class="form-control" name="studentIdCard" value="${stu_info.studentIdCard}" required>
                                </div>
                                <div class="form-group">
                                    <label>年龄</label>
                                    <input class="form-control" name="studentAge" value="${stu_info.studentAge}" required>
                                </div>
                                <div class="form-group">
                                    <label>所属学院</label>
                                    <input class="form-control" value="${stu_info.collegeName}" readonly>
                                </div>
                                <div class="form-group">
                                    <label>专业</label>
                                    <input class="form-control" value="${stu_info.specialityName}" readonly>
                                </div>
                                <div class="form-group">
                                    <label>所属专业班级</label>
                                    <input class="form-control" value="${stu_info.className}" readonly>
                                </div>
                                <input type="submit" class="btn btn-primary" value="更新">
                                <input type="reset" class="btn btn-warning" value="重置">
                            </div>
                        </div>

                    </form>

                </div>
            </div>
        </div>
    </div>
</div>

<c:if test="${message != null}">
    <script>
        alert("${message}")
    </script>

    <% session.removeAttribute("message");%>
</c:if>

<%@include file="/pages/common/foot.jsp" %>
